#include <REGX52.H>

// 定义步进电机引脚
sbit IN1 = P1^0;
sbit IN2 = P1^1;
sbit IN3 = P1^2;
sbit IN4 = P1^3;

unsigned char phaseccw[4]={0x01,0x02,0x04,0x08};//正转 电机导通相序 IN1-IN2-IN3-IN4
unsigned char phasecw[4] ={0x08,0x04,0x02,0x01};//反转 电机导通相序 IN4-IN3-IN2-IN1

// 定义延时函数
void delay(unsigned int t)
{
    while(t--);
}

void MotorData(unsigned char dat)
{
  IN1 = 1&(dat>>0);
  IN2 = 1&(dat>>1);
  IN3 = 1&(dat>>2);
  IN4 = 1&(dat>>3);
}

//顺时针转动
void MotorCW(unsigned char Speed)
{
  unsigned char i;
  for(i=0;i<4;i++)
  {
    MotorData(phaseccw[i]);
    delay(Speed);//转速调节
  }
}

//停止转动
void MotorStop(void)
{
  MotorData(0x00);
}

//逆时针转动
void MotorCCW(unsigned char Speed)
{
  unsigned char i;
  for(i=0;i<4;i++)
  {
    MotorData(phasecw[i]);
    delay(Speed);//转速调节
  }
}

void main()
{
	while(1)
	{
	}
}
